﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Windows.Xps;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Org.BouncyCastle.Asn1.Ocsp;
using be.brandweernijlen.adembescherming.dbDataSetTableAdapters;
using System.Data;
using be.brandweernijlen.ademtoestellen.Model;

namespace be.brandweernijlen.ademtoestellen.Controllers
{
    public class PDFController
    {


        public static void generateMaskerPDF(List<Masker> maskers)
        {
            using (Document doc = new Document())
            {

                
                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("tempMasker.pdf", FileMode.Create));

                doc.Open();


                foreach (Masker masker in maskers)
                {
                    Rectangle page = doc.PageSize;
                    PdfPTable head = new PdfPTable(1);
                    head.TotalWidth = page.Width;

                    Paragraph p = new Paragraph("PANORAMA NOVA MASKER");
                    p.Font.Size = 15;
                    p.Alignment = 0;
                    doc.Add(p);

                    // Datum 

                    PdfPTable dateTable = new PdfPTable(1);
                    dateTable.HorizontalAlignment = 0;
                    dateTable.WidthPercentage = 90;
                    // then set the column's __relative__ widths
                    dateTable.SetWidths(new Single[] { 1 });
                    dateTable.SpacingBefore = 10;

                    PdfPCell cell = new PdfPCell(new Phrase("Datum: " + masker.Datum.ToLongDateString()));
                    dateTable.AddCell(cell);

                    doc.Add(dateTable);

                    PdfPTable mainTable = new PdfPTable(2);
                    mainTable.HorizontalAlignment = 0;
                    mainTable.WidthPercentage = 90;
                    // then set the column's __relative__ widths
                    mainTable.SetWidths(new Single[] { 1, 2 });
                    mainTable.SpacingBefore = 10;

                    PdfPCell cellLeft = new PdfPCell(new Phrase("Naam:"));
                    PdfPCell cellMiddle = new PdfPCell(new Phrase(""));
                    PdfPCell cellRight = new PdfPCell(new Phrase(masker.Verantwoordelijke));

                    mainTable.AddCell(cellLeft);
                    mainTable.AddCell(cellRight);

                    cellLeft = new PdfPCell(new Phrase("Nummer masker:"));
                    cellRight = new PdfPCell(new Phrase(masker.NummerMasker));
                    mainTable.AddCell(cellLeft);
                    mainTable.AddCell(cellRight);

                    cellLeft = new PdfPCell(new Phrase("Datum vorig nazicht"));
                    cellRight = new PdfPCell(new Phrase(masker.VorigNazicht.ToLongDateString()));
                    mainTable.AddCell(cellLeft);
                    mainTable.AddCell(cellRight);

                    doc.Add(mainTable);
                    makeOkNotOkTable(doc, masker);

                    PdfPTable finalTable = new PdfPTable(1);
                    finalTable.HorizontalAlignment = 0;
                    finalTable.WidthPercentage = 90;
                    // then set the column's __relative__ widths
                    finalTable.SetWidths(new Single[] { 1 });
                    finalTable.SpacingBefore = 10;

                    cellLeft = new PdfPCell(new Phrase("4. Volgende onderdelen werden vervangen:"));
                    finalTable.AddCell(cellLeft);

                    cellLeft = new PdfPCell(new Phrase(masker.Vervangen));
                    finalTable.AddCell(cellLeft);

                    cellLeft = new PdfPCell(new Phrase("5. Opmerkingen"));
                    cellLeft.BorderWidthBottom = 0;
                    finalTable.AddCell(cellLeft);

                    cellLeft = new PdfPCell(new Phrase(masker.Opmerking));
                    cellLeft.BorderWidthTop = 0;
                    finalTable.AddCell(cellLeft);
                    doc.Add(finalTable);
                    doc.NewPage();
                }
                doc.Close();

            }

        }

        public static void generateMaskerPDF(Masker masker)
        {

            using (Document doc = new Document())
            {

                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("tempMasker.pdf", FileMode.Create));

                doc.Open();


                Rectangle page = doc.PageSize;
                PdfPTable head = new PdfPTable(1);
                head.TotalWidth = page.Width;
                
                Paragraph p = new Paragraph("PANORAMA NOVA MASKER");
                p.Font.Size = 15;
                p.Alignment = 0;
                doc.Add(p);

                // Datum 

                PdfPTable dateTable = new PdfPTable(1);
                dateTable.HorizontalAlignment = 0;
                dateTable.WidthPercentage = 90;
                // then set the column's __relative__ widths
                dateTable.SetWidths(new Single[] { 1 });
                dateTable.SpacingBefore = 10;

                PdfPCell cell = new PdfPCell(new Phrase("Datum: " + masker.Datum.ToLongDateString()));
                dateTable.AddCell(cell);

                doc.Add(dateTable);

                PdfPTable mainTable = new PdfPTable(2);
                mainTable.HorizontalAlignment = 0;
                mainTable.WidthPercentage = 90;
                // then set the column's __relative__ widths
                mainTable.SetWidths(new Single[] { 1, 2 });
                mainTable.SpacingBefore = 10;

                PdfPCell cellLeft = new PdfPCell(new Phrase("Naam:"));
                PdfPCell cellMiddle = new PdfPCell(new Phrase(""));
                PdfPCell cellRight = new PdfPCell(new Phrase(masker.Verantwoordelijke));

                mainTable.AddCell(cellLeft);
                mainTable.AddCell(cellRight);
                
                cellLeft = new PdfPCell(new Phrase("Nummer masker:"));
                cellRight = new PdfPCell(new Phrase(masker.NummerMasker));
                mainTable.AddCell(cellLeft);
                mainTable.AddCell(cellRight);

                cellLeft = new PdfPCell(new Phrase("Datum vorig nazicht"));
                cellRight = new PdfPCell(new Phrase(masker.VorigNazicht.ToLongDateString()));
                mainTable.AddCell(cellLeft);
                mainTable.AddCell(cellRight);

                doc.Add(mainTable);
                makeOkNotOkTable(doc, masker);

                PdfPTable finalTable = new PdfPTable(1);
                finalTable.HorizontalAlignment = 0;
                finalTable.WidthPercentage = 90;
                // then set the column's __relative__ widths
                finalTable.SetWidths(new Single[] { 1 });
                finalTable.SpacingBefore = 10;

                cellLeft = new PdfPCell(new Phrase("4. Volgende onderdelen werden vervangen:"));
                finalTable.AddCell(cellLeft);

                cellLeft = new PdfPCell(new Phrase(masker.Vervangen));
                finalTable.AddCell(cellLeft);

                cellLeft = new PdfPCell(new Phrase("5. Opmerkingen"));
                cellLeft.BorderWidthBottom = 0;
                finalTable.AddCell(cellLeft);

                cellLeft = new PdfPCell(new Phrase(masker.Opmerking));
                cellLeft.BorderWidthTop= 0;
                finalTable.AddCell(cellLeft);
                doc.Add(finalTable);
                doc.Close();

            }

        }

        public static void generateAdemLuchtToestelPDF(List<AdemLuchtToestel> ademLuchtToestellen)
        {

            using (Document doc = new Document())
            {

                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("tempAdemLuchtToestel.pdf", FileMode.Create));

                doc.Open();

                foreach (AdemLuchtToestel ademLuchtToestel in ademLuchtToestellen)
                {
                    Rectangle page = doc.PageSize;
                    PdfPTable head = new PdfPTable(1);
                    head.TotalWidth = page.Width;

                    Paragraph p = new Paragraph("Ademluchttoestel");
                    p.Font.Size = 15;
                    p.Alignment = 0;
                    doc.Add(p);

                    // Datum 

                    PdfPTable dateTable = new PdfPTable(1);
                    dateTable.HorizontalAlignment = 0;
                    dateTable.WidthPercentage = 90;
                    // then set the column's __relative__ widths
                    dateTable.SetWidths(new Single[] { 1 });
                    dateTable.SpacingBefore = 10;

                    PdfPCell cell = new PdfPCell(new Phrase("Datum: " + ademLuchtToestel.Datum.ToLongDateString()));
                    dateTable.AddCell(cell);

                    doc.Add(dateTable);

                    PdfPTable mainTable = new PdfPTable(2);
                    mainTable.HorizontalAlignment = 0;
                    mainTable.WidthPercentage = 90;
                    // then set the column's __relative__ widths
                    mainTable.SetWidths(new Single[] { 1, 2 });
                    mainTable.SpacingBefore = 10;

                    PdfPCell cellLeft = new PdfPCell(new Phrase("Naam:"));
                    PdfPCell cellMiddle = new PdfPCell(new Phrase(""));
                    PdfPCell cellRight = new PdfPCell(new Phrase(ademLuchtToestel.Verantwoordelijke));

                    mainTable.AddCell(cellLeft);
                    mainTable.AddCell(cellRight);

                    cellLeft = new PdfPCell(new Phrase("Nummer fles:"));
                    cellRight = new PdfPCell(new Phrase(ademLuchtToestel.NummerFles));
                    mainTable.AddCell(cellLeft);
                    mainTable.AddCell(cellRight);


                    cellLeft = new PdfPCell(new Phrase("Nummer draagstel:"));
                    cellRight = new PdfPCell(new Phrase(ademLuchtToestel.NummerDraagstel));
                    mainTable.AddCell(cellLeft);
                    mainTable.AddCell(cellRight);


                    mainTable.AddCell(cellRight);

                    doc.Add(mainTable);
                    makeOkNotOkTableALT(doc, ademLuchtToestel);

                    PdfPTable finalTable = new PdfPTable(1);
                    finalTable.HorizontalAlignment = 0;
                    finalTable.WidthPercentage = 90;
                    // then set the column's __relative__ widths
                    finalTable.SetWidths(new Single[] { 1 });
                    finalTable.SpacingBefore = 10;

                    cellLeft = new PdfPCell(new Phrase("4. Volgende onderdelen werden vervangen:"));
                    finalTable.AddCell(cellLeft);

                    cellLeft = new PdfPCell(new Phrase(ademLuchtToestel.Vervangen));
                    finalTable.AddCell(cellLeft);

                    cellLeft = new PdfPCell(new Phrase("5. Opmerkingen"));
                    cellLeft.BorderWidthTop = 0;
                    cellLeft.BorderWidthBottom = 0;
                    finalTable.AddCell(cellLeft);

                    cellLeft = new PdfPCell(new Phrase(ademLuchtToestel.Opmerking));
                    cellLeft.BorderWidthTop = 0;
                    finalTable.AddCell(cellLeft);
                    doc.Add(finalTable);
                    doc.NewPage();
                }
                doc.Close();

            }

        }


        public static void generateAdemLuchtToestelPDF(AdemLuchtToestel ademLuchtToestel)
        {

            using (Document doc = new Document())
            {

                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("tempAdemLuchtToestel.pdf", FileMode.Create));

                doc.Open();


                Rectangle page = doc.PageSize;
                PdfPTable head = new PdfPTable(1);
                head.TotalWidth = page.Width;

                Paragraph p = new Paragraph("Ademluchttoestel");
                p.Font.Size = 15;
                p.Alignment = 0;
                doc.Add(p);

                // Datum 

                PdfPTable dateTable = new PdfPTable(1);
                dateTable.HorizontalAlignment = 0;
                dateTable.WidthPercentage = 90;
                // then set the column's __relative__ widths
                dateTable.SetWidths(new Single[] { 1 });
                dateTable.SpacingBefore = 10;

                PdfPCell cell = new PdfPCell(new Phrase("Datum: " + ademLuchtToestel.Datum.ToLongDateString()));
                dateTable.AddCell(cell);

                doc.Add(dateTable);

                PdfPTable mainTable = new PdfPTable(2);
                mainTable.HorizontalAlignment = 0;
                mainTable.WidthPercentage = 90;
                // then set the column's __relative__ widths
                mainTable.SetWidths(new Single[] { 1, 2 });
                mainTable.SpacingBefore = 10;

                PdfPCell cellLeft = new PdfPCell(new Phrase("Naam:"));
                PdfPCell cellMiddle = new PdfPCell(new Phrase(""));
                PdfPCell cellRight = new PdfPCell(new Phrase(ademLuchtToestel.Verantwoordelijke));

                mainTable.AddCell(cellLeft);
                mainTable.AddCell(cellRight);

                cellLeft = new PdfPCell(new Phrase("Nummer fles:"));
                cellRight = new PdfPCell(new Phrase(ademLuchtToestel.NummerFles));
                mainTable.AddCell(cellLeft);
                mainTable.AddCell(cellRight);


                cellLeft = new PdfPCell(new Phrase("Nummer draagstel:"));
                cellRight = new PdfPCell(new Phrase(ademLuchtToestel.NummerDraagstel));
                mainTable.AddCell(cellLeft);
                mainTable.AddCell(cellRight);

    
                mainTable.AddCell(cellRight);

                doc.Add(mainTable);
                makeOkNotOkTableALT(doc, ademLuchtToestel);

                PdfPTable finalTable = new PdfPTable(1);
                finalTable.HorizontalAlignment = 0;
                finalTable.WidthPercentage = 90;
                // then set the column's __relative__ widths
                finalTable.SetWidths(new Single[] { 1 });
                finalTable.SpacingBefore = 10;

                cellLeft = new PdfPCell(new Phrase("4. Volgende onderdelen werden vervangen:"));
                finalTable.AddCell(cellLeft);

                cellLeft = new PdfPCell(new Phrase(ademLuchtToestel.Vervangen));
                finalTable.AddCell(cellLeft);

                cellLeft = new PdfPCell(new Phrase("5. Opmerkingen"));
                cellLeft.BorderWidthTop = 0;
                cellLeft.BorderWidthBottom = 0;
                finalTable.AddCell(cellLeft);

                cellLeft = new PdfPCell(new Phrase(ademLuchtToestel.Opmerking));
                cellLeft.BorderWidthTop = 0;
                finalTable.AddCell(cellLeft);
                doc.Add(finalTable);
                doc.Close();

            }

        }

        public static void generatLongAutomaatPDF(List<LongAutomaat> longAutomaten)
        {

            using (Document doc = new Document())
            {

                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("tempLongAutomaat.pdf", FileMode.Create));

                doc.Open();

                foreach (LongAutomaat longAutomaat in longAutomaten)
                {
                    Rectangle page = doc.PageSize;
                    PdfPTable head = new PdfPTable(1);
                    head.TotalWidth = page.Width;

                    Paragraph p = new Paragraph("Plus Longautomaat");
                    p.Font.Size = 15;
                    p.Alignment = 0;
                    doc.Add(p);

                    // Datum 

                    PdfPTable dateTable = new PdfPTable(1);
                    dateTable.HorizontalAlignment = 0;
                    dateTable.WidthPercentage = 90;
                    // then set the column's __relative__ widths
                    dateTable.SetWidths(new Single[] { 1 });
                    dateTable.SpacingBefore = 10;

                    PdfPCell cell = new PdfPCell(new Phrase("Datum: " + longAutomaat.Datum.ToLongDateString()));
                    dateTable.AddCell(cell);

                    doc.Add(dateTable);

                    PdfPTable mainTable = new PdfPTable(2);
                    mainTable.HorizontalAlignment = 0;
                    mainTable.WidthPercentage = 90;
                    // then set the column's __relative__ widths
                    mainTable.SetWidths(new Single[] { 1, 2 });
                    mainTable.SpacingBefore = 10;

                    PdfPCell cellLeft = new PdfPCell(new Phrase("Naam:"));
                    PdfPCell cellMiddle = new PdfPCell(new Phrase(""));
                    PdfPCell cellRight = new PdfPCell(new Phrase(longAutomaat.Verantwoordelijke));

                    mainTable.AddCell(cellLeft);
                    mainTable.AddCell(cellRight);

                    cellLeft = new PdfPCell(new Phrase("Nummer longautomaat:"));
                    cellRight = new PdfPCell(new Phrase(longAutomaat.NummerLongAutomaat));
                    mainTable.AddCell(cellLeft);
                    mainTable.AddCell(cellRight);

                    cellLeft = new PdfPCell(new Phrase("Datum vorig nazicht"));
                    cellRight = new PdfPCell(new Phrase(longAutomaat.VorigNazicht.ToLongDateString()));
                    mainTable.AddCell(cellLeft);
                    mainTable.AddCell(cellRight);

                    doc.Add(mainTable);
                    makeOkNotOkTableLA(doc, longAutomaat);

                    PdfPTable finalTable = new PdfPTable(1);
                    finalTable.HorizontalAlignment = 0;
                    finalTable.WidthPercentage = 90;
                    // then set the column's __relative__ widths
                    finalTable.SetWidths(new Single[] { 1 });
                    finalTable.SpacingBefore = 10;

                    cellLeft = new PdfPCell(new Phrase("6. Volgende onderdelen werden vervangen:"));
                    finalTable.AddCell(cellLeft);

                    cellLeft = new PdfPCell(new Phrase(longAutomaat.Vervangen));
                    finalTable.AddCell(cellLeft);

                    cellLeft = new PdfPCell(new Phrase("7. Opmerkingen"));
                    cellLeft.BorderWidthTop = 0;
                    cellLeft.BorderWidthBottom = 0;
                    finalTable.AddCell(cellLeft);

                    cellLeft = new PdfPCell(new Phrase(longAutomaat.Opmerking));
                    cellLeft.BorderWidthTop = 0;
                    finalTable.AddCell(cellLeft);
                    doc.Add(finalTable);
                    doc.Close();
                    doc.NewPage();
                }
            }

        }

        public static void generatLongAutomaatPDF(LongAutomaat longAutomaat)
        {

            using (Document doc = new Document())
            {

                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("tempLongAutomaat.pdf", FileMode.Create));

                doc.Open();


                Rectangle page = doc.PageSize;
                PdfPTable head = new PdfPTable(1);
                head.TotalWidth = page.Width;

                Paragraph p = new Paragraph("Plus Longautomaat");
                p.Font.Size = 15;
                p.Alignment = 0;
                doc.Add(p);

                // Datum 

                PdfPTable dateTable = new PdfPTable(1);
                dateTable.HorizontalAlignment = 0;
                dateTable.WidthPercentage = 90;
                // then set the column's __relative__ widths
                dateTable.SetWidths(new Single[] { 1 });
                dateTable.SpacingBefore = 10;

                PdfPCell cell = new PdfPCell(new Phrase("Datum: " + longAutomaat.Datum.ToLongDateString()));
                dateTable.AddCell(cell);

                doc.Add(dateTable);

                PdfPTable mainTable = new PdfPTable(2);
                mainTable.HorizontalAlignment = 0;
                mainTable.WidthPercentage = 90;
                // then set the column's __relative__ widths
                mainTable.SetWidths(new Single[] { 1, 2 });
                mainTable.SpacingBefore = 10;

                PdfPCell cellLeft = new PdfPCell(new Phrase("Naam:"));
                PdfPCell cellMiddle = new PdfPCell(new Phrase(""));
                PdfPCell cellRight = new PdfPCell(new Phrase(longAutomaat.Verantwoordelijke));

                mainTable.AddCell(cellLeft);
                mainTable.AddCell(cellRight);

                cellLeft = new PdfPCell(new Phrase("Nummer longautomaat:"));
                cellRight = new PdfPCell(new Phrase(longAutomaat.NummerLongAutomaat));
                mainTable.AddCell(cellLeft);
                mainTable.AddCell(cellRight);

                cellLeft = new PdfPCell(new Phrase("Datum vorig nazicht"));
                cellRight = new PdfPCell(new Phrase(longAutomaat.VorigNazicht.ToLongDateString()));
                mainTable.AddCell(cellLeft);
                mainTable.AddCell(cellRight);

                doc.Add(mainTable);
                makeOkNotOkTableLA(doc, longAutomaat);

                PdfPTable finalTable = new PdfPTable(1);
                finalTable.HorizontalAlignment = 0;
                finalTable.WidthPercentage = 90;
                // then set the column's __relative__ widths
                finalTable.SetWidths(new Single[] { 1 });
                finalTable.SpacingBefore = 10;

                cellLeft = new PdfPCell(new Phrase("6. Volgende onderdelen werden vervangen:"));
                finalTable.AddCell(cellLeft);

                cellLeft = new PdfPCell(new Phrase(longAutomaat.Vervangen));
                finalTable.AddCell(cellLeft);

                cellLeft = new PdfPCell(new Phrase("7. Opmerkingen"));
                cellLeft.BorderWidthTop = 0;
                cellLeft.BorderWidthBottom = 0;
                finalTable.AddCell(cellLeft);

                cellLeft = new PdfPCell(new Phrase(longAutomaat.Opmerking));
                cellLeft.BorderWidthTop = 0;
                finalTable.AddCell(cellLeft);
                doc.Add(finalTable);
                doc.Close();

            }

        }


        private static void makeOkNotOkTableALT(Document doc, AdemLuchtToestel ademLuchtToestel)
        {
            PdfPTable okTable1 = new PdfPTable(3);
            PdfPCell cellLeft;
            PdfPCell cellMiddle;
            PdfPCell cellRight;

            okTable1.HorizontalAlignment = 0;
            okTable1.WidthPercentage = 70;
            // then set the column's __relative__ widths
            okTable1.SetWidths(new Single[] { 3, 1, 1 });
            okTable1.SpacingBefore = 10;

            cellLeft = new PdfPCell(new Phrase("1. Visuele inspectie:"));
            cellMiddle = new PdfPCell(new Phrase("OK"));
            cellRight = new PdfPCell(new Phrase("NIET OK"));
            cellLeft.HorizontalAlignment = 0;
            cellMiddle.HorizontalAlignment = 1;
            cellRight.HorizontalAlignment = 1;
            okTable1.AddCell(cellLeft);
            okTable1.AddCell(cellMiddle);
            okTable1.AddCell(cellRight);


            makeOkRow(okTable1, "     - Draagplaat ", ademLuchtToestel.Draagplaat);
            makeOkRow(okTable1, "     - Draagriemen", ademLuchtToestel.Draagriemen);
            makeOkRow(okTable1, "     - Ontspanner", ademLuchtToestel.Ontspanner);
            makeOkRow(okTable1, "     - Fluitsignaal", ademLuchtToestel.Fluitsignaal);
            makeOkRow(okTable1, "     - Flesaansluiting", ademLuchtToestel.Flesaansluiting);
            makeOkRow(okTable1, "     - Spanband fles", ademLuchtToestel.SpanbandFles);

            doc.Add(okTable1);


            PdfPTable okTable2 = new PdfPTable(3);
            okTable2.HorizontalAlignment = 0;
            okTable2.WidthPercentage = 70;
            // then set the column's __relative__ widths
            okTable2.SetWidths(new Single[] { 3, 1, 1 });
            okTable2.SpacingBefore = 10;
            makeOkRow(okTable2, "2. Druk ademluchtfles min. 270 bar", ademLuchtToestel.DrukAdemluchtfles);
            doc.Add(okTable2);

            PdfPTable okTable3 = new PdfPTable(3);
            okTable3.HorizontalAlignment = 0;
            okTable3.WidthPercentage = 70;
            // then set the column's __relative__ widths
            okTable3.SetWidths(new Single[] { 3, 1, 1 });
            okTable3.SpacingBefore = 10;
            makeOkRow(okTable3, "3. Fluitsignaal 50 bar - 60 bar", ademLuchtToestel.FluitsignaalBar);
            doc.Add(okTable3);

        }

    

        private static void makeOkNotOkTableLA(Document doc, LongAutomaat longAutomaat)
        {
            PdfPTable okTable1 = new PdfPTable(3);
            PdfPCell cellLeft;
            PdfPCell cellMiddle;
            PdfPCell cellRight;

            okTable1.HorizontalAlignment = 0;
            okTable1.WidthPercentage = 90;
            // then set the column's __relative__ widths
            okTable1.SetWidths(new Single[] { 4, 1, 1 });
            okTable1.SpacingBefore = 10;

            cellLeft = new PdfPCell(new Phrase("1. Visuele inspectie:"));
            cellMiddle = new PdfPCell(new Phrase("OK"));
            cellRight = new PdfPCell(new Phrase("NIET OK"));
            cellLeft.HorizontalAlignment = 0;
            cellMiddle.HorizontalAlignment = 1;
            cellRight.HorizontalAlignment = 1;
            okTable1.AddCell(cellLeft);
            okTable1.AddCell(cellMiddle);
            okTable1.AddCell(cellRight);


            makeOkRow(okTable1, "     - O-ring longautomaat", longAutomaat.ORing);
            makeOkRow(okTable1, "     - Membraan longautomaat", longAutomaat.Membraan);


            doc.Add(okTable1);


            PdfPTable okTable2 = new PdfPTable(3);
            okTable2.HorizontalAlignment = 0;
            okTable2.WidthPercentage = 90;
            // then set the column's __relative__ widths
            okTable2.SetWidths(new Single[] {4, 1, 1 });
            okTable2.SpacingBefore = 10;
            makeOkRow(okTable2, "2. Dichtheid longautomaat 7mbar +/- 1 mbar in 15 sec", longAutomaat.Dichtheid);
            doc.Add(okTable2);

            PdfPTable okTable3 = new PdfPTable(3);
            okTable3.HorizontalAlignment = 0;
            okTable3.WidthPercentage = 90;
            // then set the column's __relative__ widths
            okTable3.SetWidths(new Single[] { 4, 1, 1 });
            okTable3.SpacingBefore = 10;
            makeOkRow(okTable3, "3. Aanspreekdruk longautomaat", longAutomaat.Aanspreekdruk);
            doc.Add(okTable3);


            PdfPTable okTable4 = new PdfPTable(3);
            okTable4.HorizontalAlignment = 0;
            okTable4.WidthPercentage = 90;
            // then set the column's __relative__ widths
            okTable4.SetWidths(new Single[] { 4, 1, 1 });
            okTable4.SpacingBefore = 10;
            makeOkRow(okTable4, "4. Statische overdruk longautomaat tussen 1 en 3,9 mbar", longAutomaat.StatischeOverdruk);
            doc.Add(okTable4);

            PdfPTable okTable5 = new PdfPTable(3);
            okTable5.HorizontalAlignment = 0;
            okTable5.WidthPercentage = 90;
            // then set the column's __relative__ widths
            okTable5.SetWidths(new Single[] { 4, 1, 1 });
            okTable5.SpacingBefore = 10;
            makeOkRow(okTable5, "5. Invetten van o-ring longautomaat", longAutomaat.Invetten);
            doc.Add(okTable5);
        }

        private static void makeOkNotOkTable(Document doc, Masker masker)
        {
            PdfPTable okTable1 = new PdfPTable(3);
            PdfPCell cellLeft;
            PdfPCell cellMiddle;
            PdfPCell cellRight;

            okTable1.HorizontalAlignment = 0;
            okTable1.WidthPercentage = 70;
            // then set the column's __relative__ widths
            okTable1.SetWidths(new Single[] { 3, 1, 1 });
            okTable1.SpacingBefore = 10;

            cellLeft = new PdfPCell(new Phrase("1. Visuele inspectie:"));
            cellMiddle = new PdfPCell(new Phrase("OK"));
            cellRight = new PdfPCell(new Phrase("NIET OK"));
            cellLeft.HorizontalAlignment = 0;
            cellMiddle.HorizontalAlignment = 1;
            cellRight.HorizontalAlignment = 1;
            okTable1.AddCell(cellLeft);
            okTable1.AddCell(cellMiddle);
            okTable1.AddCell(cellRight);


            makeOkRow(okTable1, "     - Maskerlichaam", masker.Maskerlichaam);
            makeOkRow(okTable1, "     - Ruit", masker.Ruit);
            makeOkRow(okTable1, "     - Kopspin", masker.KopSpin);
            makeOkRow(okTable1, "     - Maskerbeugels", masker.MaskerBeugels);
            makeOkRow(okTable1, "     - Spreekmembraan", masker.Spreekmembraan);
            makeOkRow(okTable1, "     - Uitademventiel", masker.Uitademventiel);
            makeOkRow(okTable1, "     - Veer uitademventiel", masker.VeerAdemventiel);
            makeOkRow(okTable1, "     - Binnenmasker", masker.BinnenMasker);

            doc.Add(okTable1);


            PdfPTable okTable2 = new PdfPTable(3);
            okTable2.HorizontalAlignment = 0;
            okTable2.WidthPercentage = 70;
            // then set the column's __relative__ widths
            okTable2.SetWidths(new Single[] { 3, 1, 1 });
            okTable2.SpacingBefore = 10;
            makeOkRow(okTable2, "2. Dichtheidstest bij -10 mbar", masker.Dichtheidstest);
            doc.Add(okTable2);

            PdfPTable okTable3 = new PdfPTable(3);
            okTable3.HorizontalAlignment = 0;
            okTable3.WidthPercentage = 70;
            // then set the column's __relative__ widths
            okTable3.SetWidths(new Single[] { 3, 1, 1 });
            okTable3.SpacingBefore = 10;
            makeOkRow(okTable3, "3. Openingsdruk uitademventiel \n  Tussen 4,5 en 5,7 mbar", masker.OpeningsDruk);
            doc.Add(okTable3);
        }

        private static void makeOkRow(PdfPTable table, String left, Boolean value)
        {
            PdfPCell cellLeft = new PdfPCell(new Phrase(left));
            PdfPCell cellMiddle = new PdfPCell();
            PdfPCell cellRight = new PdfPCell();

            cellLeft.PaddingTop = 2;
            cellLeft.HorizontalAlignment = 0;
            cellMiddle.HorizontalAlignment = 1;
            cellRight.HorizontalAlignment = 1;
            markOKNotOk(value, cellMiddle, cellRight);

            table.AddCell(cellLeft);
            table.AddCell(cellMiddle);
            table.AddCell(cellRight);
        }

        private static void markOKNotOk(Boolean check, PdfPCell middle, PdfPCell right)
        {
            if (check)
            {
                middle.Phrase = new Phrase("X");
                right.Phrase = new Phrase("");
            }
            else
            {
                right.Phrase = new Phrase("X");
                middle.Phrase = new Phrase("");
            }
        }

    }


}



